#include <iostream>
using namespace std;

class Printer
{
public:
    static Printer *getInstance() { return pPrinter; }
    void PrintText(string text)
    {
        cout << "打印内容:" << text << endl;
        cout << "已打印次数:" << mTimes << endl;
        cout << "--------------" << endl;
        mTimes++;
    }

private:
    Printer() { mTimes = 0; }
    Printer(const Printer &) {}

private:
    static Printer *pPrinter;
    int mTimes;
};

Printer *Printer::pPrinter = new Printer;

void test()
{
    Printer *printer = Printer::getInstance();
    printer->PrintText("离职报告!");
    printer->PrintText("入职合同!");
    printer->PrintText("提交代码!");
}

//懒汉式，使用时才加载用到的时候，
//才去调用，然后才会进行构造函数的调用，该模式下是线程不安全的。

class CSingleton
{
public:
    static CSingleton *GetInstance()
    {
        if (m_pInstance == NULL)
            m_pInstance = new CSingleton();
        return m_pInstance;
    }

private:
    CSingleton(){};
    static CSingleton *m_pInstance;
};

//饿汉式，一开始就加载

class CSingleton
{
private:
    CSingleton()
    {
    }

public:
    static CSingleton *GetInstance()
    {
        static CSingleton instance;
        return &instance;
    }
};

//正确使用
class CMsBsGPSInfoStart
{
public:
    static CMsBsGPSInfoStart &GetInstance();

protected:
    CMsBsGPSInfoStart();
    ~CMsBsGPSInfoStart();

private:
    static CMsBsGPSInfoStart _instance;

private:
    //CLock m_lkMsBsGPSInfoStartFlag;
    bool m_bMsBsGPSInfoStartFlag; //

public:
    bool GetMsBsGPSInfoStart();
    bool SetMsBsGPSInfoStart(bool bIsStart);
};

CMsBsGPSInfoStart CMsBsGPSInfoStart::_instance;
CMsBsGPSInfoStart::CMsBsGPSInfoStart() : m_bMsBsGPSInfoStartFlag(false)
{
    std::cout << "enter CMsBsGPSInfoStart::CMsBsGPSInfoStart() " << endl;
}

CMsBsGPSInfoStart::~CMsBsGPSInfoStart()
{
    std::cout << "enter CMsBsGPSInfoStart::~CMsBsGPSInfoStart() " << endl;
}

CMsBsGPSInfoStart &CMsBsGPSInfoStart::GetInstance()
{
    std::cout << "CMsBsGPSInfoStart::GetInstance()" << endl;
    return _instance;
}
bool CMsBsGPSInfoStart::SetMsBsGPSInfoStart(bool bIsStart)
{
    m_bMsBsGPSInfoStartFlag = bIsStart;
    return true;
}

int main()
{
    cout << "hello" << endl;
    system("pause");
    return 0;
}
